#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int a[3][3]={1,0,0,2,0,0,3,0,0};
int top[3]={0,3,3};
main()
{
	int op;
    void help();
    void push(int,int);
	void pop(int);
	void print();
	void game();
	for(;;)
	{
    system("cls");
     printf("===============================================================\n");
     printf("||                                                           ||\n");
     printf("||                         MENU                              ||\n");
     printf("||                                                           ||\n");
     printf("||                   1 . New Game                            ||\n");
     printf("||                   2 . Help                                ||\n");
     printf("||                   3 . Exit                                ||\n");
     printf("||                                                           ||\n");
     printf("||                                              - By Fazalul ||\n");
     printf("===============================================================\n");
	printf("Enter Option:");
	scanf("%d",&op);
	if(op==1)
		{
        print();
	    game();
        }
    else if(op==2)
        help();
    else if(op==3)
         break;
    }
}
void help()
{
	system("cls");
    printf("Make the same formation of the stack you \n see to the 3rd row by any number of steps.\n");
    printf("Bigger Disks cannot be put above smaller \n ones.\n");
	printf("The columns are numbered 1,2,3 from left.\nAccomplish the task in least number of steps.\n");
	printf("   *     |     |           |     |     *  \n");
	printf("  ***    |     |    =>     |     |    *** \n");
	printf(" *****   |     |           |     |   *****\n");
	printf("==================      ==================\n");
	getch();
}
void game()
{
     for(;;)
	{
        int p,q,t=0;
		printf("\n\nPick From:");
		scanf("%d",&p);
		printf("Put In:");
		scanf("%d",&q);
		p=p-1;
		q=q-1;
		if(top[p]==3)
			printf("Invalid Move\n");
		else
		{
			if((top[q]==3)||(a[top[q]][q]>a[top[p]][p]))
			{
				push(p,q);
				pop(p);
				t+=1;
				print();
			}
			else
			printf("Invalid Move\n");
		}
		if(a[0][2]==1&&a[1][2]==2&&a[2][2]==3)
		{
			printf("Congratulations. You Win\n");
			break;
		}
	}
	getch();
}
void push(int b,int c)
{
	top[c]=top[c]-1;
	a[top[c]][c]=a[top[b]][b];
}
void pop(int b)
{
	a[top[b]][b]=0;
	top[b]=top[b]+1;
}
void print()
{
	int i,j;
	system("cls");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			switch(a[i][j])
			{
			case 1:
				printf("   *  ");
				break;
			case 2:
				printf("  *** ");
				break;
			case 3:
				printf(" *****");
				break;
			case 0:
				printf("   |  ");
				break;
			}
		}
		printf("\n");
	}
	printf("==================\n");
	printf("   1     2     3  \n");
}
